package com.biao.java8.demo;

import com.biao.java8.demo.pojo.Employee;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Stream;

public class TestStreamAPI1 {
    public static void main(String[] args) {
        // 1 可以通过Collection 系列集合提供的stream() 或者 parallelStream()
        ArrayList<String> list = new ArrayList<>();
        Stream<String> stream1 = list.stream();

        // 2 通过Arrays 的静态方法stream() 获取数组流
        Employee[] employees = new Employee[10];
        Stream<Employee> stream2 = Arrays.stream(employees);

        // 3 通过Stream 的静态方法 of()
        Stream<Object> stream3 = Stream.of("a", "b", "c");

        // 4 创建无限流(无限制)
        // 迭代
        Stream<Integer> stream4 = Stream.iterate(0, x -> x + 2);
        stream4.limit(10).forEach(System.out::println);     // 输出10个数字，递增2
        // 生产
        Stream<Double> stream5 = Stream.generate(Math::random);
        stream5.limit(5).forEach(System.out::println);      // 输出5个随机小数
    }
}
